package com.google.code.dajly;

import java.net.MalformedURLException;
import java.util.Observable;

import com.google.code.dajly.model.Entry;
import com.google.code.dajly.model.Feed;
import com.google.code.dajly.model.Model;


public class ModelTestClass  implements java.util.Observer{

	private Model _m;
	
	public ModelTestClass(){
		_m = new Model();
		_m.addObserver(this);
		
		try {
			
			_m.addFeed("http://www.corriere.it/rss/ultimora.xml");
			_m.addFeed("http://www.pigoz.eu/rss2e.xml");
//			_m.addFeed("http://www.corriere.it/rss/cronache.xml");
//			_m.addFeed("asdfgdasfuffa");
			
		} catch (MalformedURLException e) {
			// TODO MALFORMEDURL
			System.out.println("inserisci un URL valido # " + e.getMessage());
		}
			
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new ModelTestClass();
	}

	public void update(Observable arg0, Object arg1) {
		System.out.println("ricevuto un update da: "+arg0+" - argomento: "+arg1 );
		Feed _f = (Feed) arg1;
		System.out.println(_f.getTitle());
		if (_f.hasLocation()){
			System.out.print("locations: ");
			for(String _loc : _f.getLocations())
				System.out.print(_loc+"  ");
			System.out.print("\n");
		}
		if (_f.hasBusiness()){
			System.out.print("businesses: ");
			for(String _bus : _f.getBusinesses())
				System.out.print(_bus+"  ");
			System.out.print("\n");
		}
		System.out.print("\n");

		for(Entry _e : _f.getEntries()){
			System.out.println(_e.getTitle());
			System.out.println(_e.getMessage());
			System.out.println(_e.getStoryURL());
			System.out.println("");
			
		}
			
	}

}
